package cn.wolfcode.wolf2w.elasticsearch.service.impl;

import cn.wolfcode.wolf2w.elasticsearch.domain.StrategyEs;
import cn.wolfcode.wolf2w.elasticsearch.repository.StrategyESRepository;
import cn.wolfcode.wolf2w.elasticsearch.service.IStrategyESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StrategyESServiceImpl implements IStrategyESService {
    @Autowired
    private StrategyESRepository strategyESRepository;

    @Autowired
    private ElasticsearchTemplate template;

    @Override
    public void save(StrategyEs strategyES) {
    strategyESRepository.save(strategyES);
    }

    @Override
    public void update(StrategyEs strategyES) {
    strategyESRepository.save(strategyES);
    }

    @Override
    public void delete(String id) {
    strategyESRepository.deleteById(id);
    }

    @Override
    public StrategyEs get(String id) {
        return strategyESRepository.findById(id).orElse(null);
    }

    @Override
    public List<StrategyEs> listAll() {
        Iterable<StrategyEs> iterable = strategyESRepository.findAll();
        ArrayList<StrategyEs> list = new ArrayList<>();
        iterable.forEach(a -> list.add(a));
        return list;
    }
}